package com.fz.servlet;

import com.fz.mapper.StudentMapper;
import com.fz.mybatis.MyHelper;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by webrx on 2017-08-25.
 */
@WebServlet("/show.action")
public class Show extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        MyHelper mh = new MyHelper();

        StudentMapper sdao = mh.getSession().getMapper(StudentMapper.class);
        if(req.getParameter("did")!=null){
            int id = Integer.parseInt(req.getParameter("did"));
            sdao.deleteById(id);
            mh.getSession().commit();
        }
        req.setAttribute("students",sdao.query());
        req.getRequestDispatcher("Show.jsp").forward(req,resp);
    }
}
